package cn.wolfcode.wolf2w.business.listen;

import cn.wolfcode.wolf2w.api.domain.Destination;
import cn.wolfcode.wolf2w.api.domain.DestinationSearch;
import cn.wolfcode.wolf2w.business.repository.DestinationRepository;
import com.alibaba.fastjson.JSON;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 浪兎兎
 * @since 2025-06-16 13:38
 */
@Component
public class DestinationListener {
    @Autowired
    private DestinationRepository destinationRepository;
    @RabbitListener(queues = {"destinationQueue"})
    public void onMessage(String message) {
        Destination destination = JSON.parseObject(message, Destination.class);
        DestinationSearch destinationSearch = new DestinationSearch();
        BeanUtils.copyProperties(destination, destinationSearch);
        destinationRepository.save(destinationSearch);
    }
}
